import { useClipboard } from '@vueuse/core';

/**
 * 复制
 */
export function useClipboardHelper() {
  const { copy, isSupported } = useClipboard({ legacy: true });

  const copyClipboard = async (text: string) => {
    if (!isSupported) {
      ElToast.error('您的浏览器不支持复制');
    } else {
      try {
        await copy(text);
        ElToast.success('复制成功');
      } catch (error) {
        ElToast.error('复制失败');
      }
    }
  };

  return { copyClipboard };
}
